home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000058_icon-group-sender_Mon Mar 12 12:43:04 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f2CJgiY18384
  4.     for icon-group-addresses; Mon, 12 Mar 2001 12:42:44 -0700 (MST)
  5. Message-Id: <200103121942.f2CJgiY18384@baskerville.CS.Arizona.EDU>
  6. Date: Mon, 12 Mar 2001 10:35:58 -0600
  7. From: gep2@terabites.com
  8. Subject: Re: New Scientist Puzzle
  9. To: icon-group@cs.arizona.edu
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11. Status: RO
  12. Content-Length: 2911
  13.  
  14. Several things I don't understand about your solution in Delphi.
  15.  
  16. 1)  Why do you only loop to 89 and not 99?
  17.  
  18. 2)  What's with the A<>B thing?  
  19.  
  20. 3)  I don't see where/if your solution addresses the "uniquely identifies" 
  21. constraint.
  22.  
  23. 4)  Why do you only check I & J values that are digit-wise mirror images of each 
  24. other?  That doesn't look 'right', either.
  25.  
  26. Can you explain?
  27.  
  28. <---- Begin Forwarded Message ---->
  29. Return-Path: <icon-group-sender@cs.arizona.edu>
  30. From: jwormsley@debitek.com (Jeffrey A. Wormsley)
  31. Subject: Re: New Scientist Puzzle
  32. Date: Mon, 12 Mar 2001 15:03:36 -0000
  33. To: icon-group@CS.Arizona.EDU
  34.  
  35. Can't help be throw a very verbose and fly right at it Delphi solution 
  36. in...  Certaily isn't 5 lines like the K solution, but then I can't read 
  37. the K solution ;^).
  38.  
  39. unit Main;
  40.  
  41. interface
  42.  
  43. uses
  44.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  45.   StdCtrls;
  46.  
  47. type
  48.   TForm1 = class(TForm)
  49.     Memo1: TMemo;
  50.     Button1: TButton;
  51.     procedure Button1Click(Sender: TObject);
  52.   private
  53.     { Private declarations }
  54.     Function  Match(I,J : Integer): Boolean;
  55.     Procedure FindMatches;
  56.   public
  57.     { Public declarations }
  58.   end;
  59.  
  60. var
  61.   Form1: TForm1;
  62.  
  63. implementation
  64.  
  65. {$R *.DFM}
  66.  
  67. Function TForm1.Match(I,J : Integer): Boolean;
  68. Var S : String;
  69.     K, L : Byte;
  70. Begin
  71.  Result := False;                              // Assume no match
  72.  S := IntToStr(Sqr(I)) + IntToStr(Sqr(J));     // Build string
  73.  If (S[3] <> S[6]) or (S[5] <> S[8]) then      // Check the E's and N's
  74.   Exit;                                        // Exit if not matched
  75.  S := S[1] + S[2] + S[3] + S[4] + S[5] + S[7]; // Remove dup E's and N's
  76.  For K := 1 to Length(S) - 1 Do                // Scan for dups
  77.   For L := K + 1 to Length(S) Do
  78.    If S[K] = S[L] then                         // If dup found
  79.     Exit;                                      // Exit
  80.  Result := True;                               // Good match if this far
  81. End;
  82.  
  83. Procedure TForm1.FindMatches;
  84. Var I, J, A, B : Byte;
  85. Begin
  86.  For I := 34 to 89 do
  87.   Begin
  88.    A := I div 10; B := I mod 10;               // Get digits
  89.    If A <> B then                              // Can't work if equal
  90.     Begin
  91.      J := A + (B * 10);                        // Transpose digits
  92.      If Match(I,J) then                        // Check for match
  93.       Memo1.Lines.Add( 'VIER = ' + IntToStr(Sqr(I)) +
  94.                       ' NEUN = ' + IntToStr(Sqr(J)) +
  95.                       ' (' + IntToStr(I) + ',' + IntToStr(J) + ')');
  96.     End;
  97.   End;
  98. End;
  99.  
  100. procedure TForm1.Button1Click(Sender: TObject);
  101. begin
  102.  FindMatches;
  103. end;
  104.  
  105. end.
  106.  
  107. Jeff.
  108.  
  109.  
  110.  
  111. <----  End Forwarded Message  ---->
  112.  
  113. Gordon Peterson                  http://personal.terabites.com/
  114. Support the Anti-SPAM Amendment!  Join at http://www.cauce.org/
  115. 12/19/98: Partisan Republicans scornfully ignore the voters they "represent".
  116. 12/09/00: the date the Republican Party took down democracy in America.
  117.  
  118.